package it.hive.model.sound.trackAnalysis;

import java.io.File;
import java.io.IOException;

import com.echonest.api.v4.EchoNestAPI;
import com.echonest.api.v4.EchoNestException;
import com.echonest.api.v4.Track;

public class AnalizzatoreTraccia {

	public String analizzaTraccia(File f) {
		EchoNestAPI en;
		try {
			en = new EchoNestAPI("7XTKBQXIQMKVOI3E3");
			// en.identifySongs(new Params().);
			Track track = en.uploadTrack(f);
			track.waitForAnalysis(10000);

			// if (track.getStatus() == Track.AnalysisStatus.COMPLETE) {

			System.out.println("Nome: " + track.getTitle());
			System.out.println("Tempo: " + track.getTempo());
			System.out.println("Danceability: " + track.getDanceability());
			System.out.println("Speechiness: " + track.getSpeechiness());
			System.out.println("Liveness: " + track.getLiveness());
			System.out.println("Energy: " + track.getEnergy());
			System.out.println("Loudness: " + track.getLoudness());
			System.out.println();
			System.out.println("Beat start times:");

			// TrackAnalysis analysis = track.getAnalysis();
			// for (TimedEvent beat : analysis.getBeats()) {
			// System.out.println("beat " + beat.getStart());
			// }
			// } else {
			// System.err.println("Trouble analysing track " + track.getStatus());
			// }

		} catch (IOException | EchoNestException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return null;

	}

	public static void main(String[] args) {
		System.setProperty("http.proxyHost", "201.91.28.20");
		System.setProperty("http.proxyPort", "8080");
		// File downloadDirectory = new File("D:\\Desktop\\Where.mp3");
		File downloadDirectory = new File("D:\\Desktop\\drea.mp3");
		AnalizzatoreTraccia analizzatore = new AnalizzatoreTraccia();
		analizzatore.analizzaTraccia(downloadDirectory);
	}

}
